home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4741 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.8 KB

  1. Path: qualcomm.com!usenet
  2. From: nabbasi@qualcomm.com (Nasser Abbasi)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How to handle error in constructor
  5. Date: 31 Jan 1996 22:54:29 GMT
  6. Organization: QUALCOMM
  7. Distribution: world
  8. Message-ID: <4eorv5$416@qualcomm.com>
  9. References: <DLyyIM.5EG@teslab.lab.oz.au> <4eo6n6$rbp@cnn.exu.ericsson.se>
  10. NNTP-Posting-Host: nabbasi.qualcomm.com
  11. Mime-Version: 1.0
  12. X-Newsreader: WinVN 0.93.14
  13.  
  14. In article <4eo6n6$rbp@cnn.exu.ericsson.se>, ebumow@ebu.ericsson.com 
  15. says...
  16.  
  17. >
  18. >That's because exception handling is the way to handle errors using
  19. >C++ nowadays.
  20. >
  21.  
  22. Exception handling is a clean and natural way to handle errors in the
  23. program. No one will argue with that. However, using exception handling
  24. correctly in not always that easy or simple . that is why things like 
  25. auto pointers are being considered to add to C++ ansi standard. But using 
  26. exception handling correclty is really the best solution most of the 
  27. times.
  28.  
  29. As to original question, as some one else suggested, you can instead have 
  30. an init() function that you call to do the initializations that you need 
  31. to do .
  32.  
  33. You need to make sure to protect the object against being initialized
  34. more than once if the object is gloabl !
  35.  
  36. In a single threaded application, this is easy to
  37. do via a an internal static flag inside the object private area 
  38. initialized correclty, in a multi-threaded applications, with a global 
  39. object, you need offcourse to make sure the checking on the internal flag 
  40. is in a critical section befor you do the test-and-set operation.
  41.  
  42. It is possible that intializing an object more than once can lead to a
  43. disaster !
  44.  
  45. There are many things to do something, and choosing the best and most
  46. natural way of coding something is what makes programming both an art
  47. and a sicence, and offcourse fun!
  48.  
  49. Nasser
  50.  
  51.